/*
 * igo: com.cctv.igo.admin.scheduler.common.SchedulerStartListener.java Create On 2011-5-19 下午08:28:12 By Q-Wang
 * $Revision: 1.2 $
 */
package com.ctvit.scheduler.common;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.quartz.SchedulerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ctvit.scheduler.service.ScheduleService;
import com.ctvit.framework.schedule.SchedulerManager;
import com.ctvit.framework.web.context.ContextHolder;

/**
 * @author <a href="mailto:apeidou@gmail.com">Q-Wang</a>
 *
 */
public class SchedulerStartListener implements ServletContextListener {

	private Logger logger = LoggerFactory.getLogger(SchedulerStartListener.class);

	private ServletContext servletContext;

	/**
	 * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
	 */
	@Override
	public void contextDestroyed(ServletContextEvent event) {
		try {
			SchedulerManager.shutdown();
		} catch (SchedulerException e) {
			e.printStackTrace();
			logger.error("Scheduler Shutdown Failed:", e);
		}
	}

	/**
	 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
	 */
	@Override
	public void contextInitialized(ServletContextEvent event) {
		logger.info("Scheduler Start Listener: initializing ......");
		this.servletContext = event.getServletContext();
//		ScheduleService service = ContextHolder.getBean(ScheduleService.class);
//		service.initializeSchedule();
		logger.info("Scheduler Start Successful.");
	}

}
